// 颜色变量
$primary-color: #4CAF50;
$secondary-color: #8BC34A;
$background-color: #F5F5F5;
$text-color: #333;
$shadow-color: rgba(0, 0, 0, 0.1);

// 间距变量
$spacing-xs: 4px;
$spacing-small: 8px;
$spacing-medium: 16px;
$spacing-large: 24px;

// 导航栏高度
$nav-bar-height: 44px;
$status-bar-height: 20px;

// 边框变量
$border-radius: 8px;
$border-radius-lg: 12px;
$border-color: #eee;

// 动画变量
$transition-speed: 0.3s;

// 媒体查询断点
$breakpoint-mobile: 375px;
$breakpoint-tablet: 768px;

// 混合器
@mixin mobile {
  @media screen and (max-width: $breakpoint-mobile) {
    @content;
  }
}

@mixin tablet {
  @media screen and (max-width: $breakpoint-tablet) {
    @content;
  }
}

@keyframes growing {
  0% { 
    transform: scale(1) translateY(0);
    opacity: 0.95;
  }
  50% { 
    transform: scale(1.05) translateY(-1px);
    opacity: 1;
  }
  100% { 
    transform: scale(1) translateY(0);
    opacity: 0.95;
  }
}

@keyframes countdown {
  0% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translateX(-50%) scale(1.1);
    opacity: 0.8;
  }
  100% {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

@keyframes planting {
  0% {
    transform: translateY(-20px) scale(0.8);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes pulse {
  0% { 
    box-shadow: 0 0 0 0 rgba(76,175,80,0.3);
    transform: scale(1);
  }
  70% { 
    box-shadow: 0 0 0 6px rgba(76,175,80,0);
    transform: scale(1.02);
  }
  100% { 
    box-shadow: 0 0 0 0 rgba(76,175,80,0);
    transform: scale(1);
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes shine {
  0% { background-position: -100% 0; }
  100% { background-position: 200% 0; }
}

@keyframes weather-rain {
  0% { transform: translateY(-100%); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: translateY(100%); opacity: 0; }
}

@keyframes weather-sun {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes growth-sparkle {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0; }
}

@keyframes sparkle {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1);
    opacity: 0.8;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

@keyframes rain {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(100%);
  }
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes bounce {
  0%, 100% { 
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% { 
    transform: translateY(-4px);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

@keyframes harvestPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes waterDrop {
  0% { transform: scale(0.3) translateY(-20px); opacity: 0; }
  50% { transform: scale(1) translateY(0); opacity: 1; }
  100% { transform: scale(0.8) translateY(10px); opacity: 0; }
}

@keyframes coinCollect {
  0% { transform: scale(0.5) translateY(0); opacity: 1; }
  60% { transform: scale(1.2) translateY(-40px); opacity: 1; }
  100% { transform: scale(1) translateY(-60px); opacity: 0; }
}

@keyframes toolSelect {
  0% { transform: scale(1); }
  50% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

@keyframes mature {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  50% {
    transform: scale(1.15);
    filter: brightness(1.3);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes maturityHint {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  10% {
    opacity: 1;
    transform: translateY(0);
  }
  90% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(10px);
  }
}

.page-container {
  min-height: 100vh;
  background: $background-color;
}

.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: $nav-bar-height;
  padding-top: $status-bar-height;
  background: $primary-color;
  display: flex;
  align-items: center;
  padding-left: $spacing-medium;
  padding-right: $spacing-medium;
  z-index: 100;
  
  .back-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    
    .back-icon {
      color: white;
      font-size: 24px;
    }
  }
  
  .page-title {
    flex: 1;
    color: white;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
    margin-right: 32px;
  }
}

.farm-container {
  min-height: 100vh;
  background: #f5f5f5;
  padding-top: 44px;
  box-sizing: border-box;
}

.status-bar {
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  background: white;
  padding: $spacing-medium;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 90;
  
  .status-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    .status-left {
      display: flex;
      gap: $spacing-medium;
      align-items: center;
    }
  }
}

.farm-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 12px;
  margin-top: 120px;
  
  &.expanded {
    grid-template-columns: repeat(4, 1fr);
  }
}

.farm-plot {
  position: relative;
  width: 100%;
  padding-bottom: 100%;
  background: #8BC34A;
  border-radius: $border-radius;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  overflow: hidden;
  cursor: pointer;
  
  .plot-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
  }
  
  .crop-icon {
    font-size: 32px;
    transition: transform 0.3s ease;
    
    &.growing {
      animation: growing 3s ease-in-out infinite;
      will-change: transform, opacity;
    }
    
    &.ready {
      animation: mature 1s ease-out, bounce 2s ease-in-out infinite;
      filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6));
    }
  }
  
  &.empty {
    background: #A5D6A7;
    
    &:hover {
      background: #81C784;
    }
  }
  
  &.needs-water {
    .crop-icon {
      filter: brightness(0.8);
    }
  }
  
  // 添加过渡效果
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform, box-shadow;
  
  &:active {
    transform: scale(0.95);
    transition: transform 0.1s ease-out;
  }
  
  // 添加收获动画
  &.harvesting {
    .crop-icon {
      animation: harvestPop 0.5s ease-out forwards;
    }
    
    &::after {
      content: '✨';
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 24px;
      animation: sparkle 0.8s ease-out forwards;
    }
  }
  
  // 添加浇水动画
  &.watering {
    &::before {
      content: '💧';
      position: absolute;
      top: 20%;
      left: 50%;
      transform: translateX(-50%);
      font-size: 20px;
      animation: waterDrop 0.8s ease-out forwards;
    }
  }
  
  // 添加施肥动画
  &.fertilizing {
    &::after {
      content: '🌱';
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 20px;
      animation: growth-sparkle 1s ease-out forwards;
    }
  }

  &.ready {
    .maturity-hint {
      position: absolute;
      top: -30px;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(76, 175, 80, 0.9);
      color: white;
      padding: 4px 12px;
      border-radius: 12px;
      font-size: 12px;
      white-space: nowrap;
      animation: maturityHint 3s ease-out;
      z-index: 10;
      pointer-events: none;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
      backdrop-filter: blur(4px);
    }

    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
      animation: pulse 2s infinite;
      pointer-events: none;
    }

    &:hover {
      transform: scale(1.05);
      box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
      
      .crop-icon {
        animation: bounce 0.5s ease-in-out;
      }
      
      .harvest-hint {
        opacity: 1;
        transform: translateY(0);
      }
    }

    .harvest-hint {
      position: absolute;
      bottom: 8px;
      left: 50%;
      transform: translateX(-50%) translateY(10px);
      background: rgba(0, 0, 0, 0.7);
      color: white;
      padding: 4px 8px;
      border-radius: 8px;
      font-size: 12px;
      opacity: 0;
      transition: all 0.3s ease;
      white-space: nowrap;
      pointer-events: none;
    }
  }
}

.farm-shop {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: white;
  padding: $spacing-medium;
  border-radius: $border-radius-lg;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  width: 90%;
  max-width: 600px;
  max-height: 70vh;
  
  .shop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: $spacing-medium;
    padding-bottom: $spacing-small;
    border-bottom: 1px solid $border-color;
    
    .shop-title {
      font-size: 18px;
      font-weight: 500;
    }
    
    .close-btn {
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      background: $background-color;
      cursor: pointer;
      
      &:hover {
        background: darken($background-color, 5%);
      }
    }
  }
  
  .shop-tabs {
    display: flex;
    gap: $spacing-small;
    margin-bottom: $spacing-medium;
    padding-bottom: $spacing-small;
    border-bottom: 1px solid $border-color;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
    
    .shop-tab {
      padding: $spacing-small $spacing-medium;
      color: $text-color;
      opacity: 0.6;
      transition: all 0.3s ease;
      display: flex;
      align-items: center;
      gap: $spacing-small;
      
      &.active {
        opacity: 1;
        color: $primary-color;
        border-bottom: 2px solid $primary-color;
      }
      
      .tab-icon {
        font-size: 20px;
      }
      
      .tab-badge {
        background: $primary-color;
        color: white;
        font-size: 12px;
        padding: 2px 6px;
        border-radius: 10px;
        margin-left: 4px;
      }
    }
  }
  
  .shop-items {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: $spacing-medium;
    padding: $spacing-small;
    overflow-y: auto;
    max-height: 50vh;
    
    .shop-item {
      background: $background-color;
      border-radius: $border-radius;
      padding: $spacing-small;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: $spacing-small;
      transition: all 0.3s ease;
      cursor: pointer;
      
      &:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      }
      
      &.selected {
        background: rgba($primary-color, 0.1);
        border: 1px solid $primary-color;
      }
      
      .item-icon {
        font-size: 32px;
        width: 48px;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: white;
        border-radius: $border-radius;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
      }
      
      .item-info {
        text-align: center;
        
        .item-name {
          font-size: 14px;
          font-weight: 500;
          margin-bottom: 4px;
        }
        
        .item-price {
          font-size: 12px;
          color: $text-color;
          opacity: 0.8;
        }
        
        .item-bonus {
          font-size: 10px;
          color: $primary-color;
        }
        
        .item-stock {
          font-size: 10px;
          color: #F44336;
          margin-top: 2px;
        }
      }
    }
  }
}

.farm-plot {
  .growth-time {
    position: absolute;
    bottom: $spacing-small;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 2;
    backdrop-filter: blur(4px);
    
    &.urgent {
      background: rgba(244, 67, 54, 0.8);
      animation: pulse 1s ease-in-out infinite;
    }
    
    &.ready {
      background: rgba(76, 175, 80, 0.8);
    }
  }
  
  .growth-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    overflow: hidden;
    
    .progress-bar {
      height: 100%;
      background: linear-gradient(90deg, $primary-color, lighten($primary-color, 10%));
      transition: width 0.3s linear;
      position: relative;
      
      &:after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(
          90deg,
          transparent 0%,
          rgba(255, 255, 255, 0.4) 50%,
          transparent 100%
        );
        animation: shine 2s linear infinite;
      }
    }
  }
}

.weather-effect {
  &.weather-rain {
    .rain-drop {
      position: absolute;
      width: 2px;
      height: 10px;
      background: rgba(255,255,255,0.6);
      
      @for $i from 1 through 10 {
        &:nth-child(#{$i}) {
          left: 10% * $i;
          animation: rain 1s linear ($i * 0.1s) infinite;
        }
      }
      
      filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
    }
  }
  
  &.weather-sun {
    .sun-ray {
      position: absolute;
      top: -20%;
      left: -20%;
      right: -20%;
      bottom: -20%;
      background: radial-gradient(circle, rgba(255,235,59,0.2) 0%, transparent 70%);
      animation: rotate 10s linear infinite;
      opacity: 0.6;
      mix-blend-mode: screen;
    }
  }
}

// 添加背包样式
.inventory {
  position: fixed;
  right: $spacing-medium;
  bottom: 100px;
  background: white;
  border-radius: $border-radius;
  padding: $spacing-small;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  
  .inventory-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: $primary-color;
    border-radius: $border-radius;
    cursor: pointer;
    transition: all 0.3s ease;
    
    &:hover {
      transform: scale(1.1) translateY(-5px);
      box-shadow: 0 6px 16px rgba($primary-color, 0.3);
    }
    
    .inventory-icon {
      font-size: 24px;
      color: white;
    }
    
    .inventory-badge {
      position: absolute;
      top: -5px;
      right: -5px;
      background: #F44336;
      color: white;
      font-size: 12px;
      padding: 2px 6px;
      border-radius: 10px;
      font-weight: bold;
      transition: all 0.3s ease;
      
      &.new-item {
        animation: pulse 1s infinite;
      }
    }
  }
}

// 添加仓库弹窗样式
.inventory-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: $border-radius-lg;
  padding: $spacing-large;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: $spacing-medium;
  z-index: 1000;
  
  .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: $spacing-medium;
    
    .modal-title {
      font-size: 18px;
      font-weight: 500;
    }
    
    .close-btn {
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      background: $background-color;
      cursor: pointer;
      
      &:hover {
        background: darken($background-color, 5%);
      }
    }
  }
  
  .inventory-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: $spacing-small;
    overflow-y: auto;
    padding: $spacing-small;
    
    .inventory-item {
      position: relative;
      background: $background-color;
      border-radius: $border-radius;
      padding: $spacing-small;
      aspect-ratio: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 4px;
      cursor: pointer;
      transition: all 0.3s ease;
      
      &:hover {
        transform: scale(1.05);
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      }
      
      .item-icon {
        font-size: 24px;
      }
      
      .item-count {
        position: absolute;
        bottom: 4px;
        right: 4px;
        font-size: 12px;
        font-weight: 500;
        color: $text-color;
      }
    }
  }
  
  .inventory-stats {
    display: flex;
    justify-content: space-between;
    padding: $spacing-medium;
    background: $background-color;
    border-radius: $border-radius;
    margin-top: auto;
    
    .stat-item {
      display: flex;
      align-items: center;
      gap: $spacing-small;
      
      .stat-icon {
        font-size: 20px;
      }
      
      .stat-value {
        font-size: 14px;
        font-weight: 500;
      }
    }
  }
}

// 添加成就系统样式
.achievements {
  position: fixed;
  left: $spacing-medium;
  bottom: 100px;
  background: white;
  border-radius: $border-radius;
  padding: $spacing-small;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  
  .achievements-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FFC107;
    border-radius: $border-radius;
    cursor: pointer;
    transition: all 0.3s ease;
    
    &:hover {
      transform: scale(1.1) rotate(-5deg);
      box-shadow: 0 6px 16px rgba(#FFC107, 0.3);
    }
    
    .achievements-icon {
      font-size: 24px;
      color: white;
    }
    
    .new-achievement {
      position: absolute;
      top: -5px;
      right: -5px;
      width: 10px;
      height: 10px;
      background: #F44336;
      border-radius: 50%;
      animation: pulse 1s infinite;
    }
  }
}

// 商店样式
.shop-button {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  background: $primary-color;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  .shop-icon {
    font-size: 32px;
    color: white;
  }
  
  &:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 16px rgba($primary-color, 0.3);
  }
  
  &:active {
    transform: scale(0.95);
  }
}

// 工具栏样式
.tool-bar {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: white;
  border-radius: $border-radius;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 80;
  
  .tool-item {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: $border-radius;
    margin-bottom: 8px;
    cursor: pointer;
    
    &:last-child {
      margin-bottom: 0;
    }
    
    &:hover {
      background: rgba($primary-color, 0.1);
      transform: translateX(-5px);
    }
    
    &.active {
      animation: toolSelect 0.3s ease-out;
      box-shadow: 0 2px 8px rgba($primary-color, 0.3);
      
      &:hover {
        transform: translateX(-5px) scale(1.05);
      }
    }
  }
}

// 金币收集动画
.coin-collect {
  position: absolute;
  pointer-events: none;
  animation: coinCollect 1s ease-out forwards;
  color: #FFD700;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
} 